﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.serverpackets;

namespace l1cs.server.model.skill
{
    class L1BuffUtil
    {
        private static Logger _log = Logger.getLogger( typeof( L1BuffUtil ).FullName );

        public static void haste( L1PcInstance pc, int timeMillis )
        {
            pc.setSkillEffect( L1SkillId.STATUS_HASTE, timeMillis );

            int objId = pc.getId();
            pc.sendPackets( new S_SkillHaste( objId, 1, timeMillis / 1000 ) );
            pc.broadcastPacket( new S_SkillHaste( objId, 1, 0 ) );
            pc.sendPackets( new S_SkillSound( objId, 191 ) );
            pc.broadcastPacket( new S_SkillSound( objId, 191 ) );
            pc.setMoveSpeed( 1 );
        }

        public static void brave( L1PcInstance pc, int timeMillis )
        {
            if ( pc.hasSkillEffect( L1SkillId.STATUS_ELFBRAVE ) )
            { // エルヴンワッフルとは重複しない
                pc.killSkillEffectTimer( L1SkillId.STATUS_ELFBRAVE );
                pc.sendPackets( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.broadcastPacket( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.setBraveSpeed( 0 );
            }
            if ( pc.hasSkillEffect( L1SkillId.HOLY_WALK ) )
            { // ホーリーウォークとは重複しない
                pc.killSkillEffectTimer( L1SkillId.HOLY_WALK );
                pc.sendPackets( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.broadcastPacket( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.setBraveSpeed( 0 );
            }
            if ( pc.hasSkillEffect( L1SkillId.MOVING_ACCELERATION ) )
            { // ムービングアクセレーションとは重複しない
                pc.killSkillEffectTimer( L1SkillId.MOVING_ACCELERATION );
                pc.sendPackets( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.broadcastPacket( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.setBraveSpeed( 0 );
            }
            if ( pc.hasSkillEffect( L1SkillId.WIND_WALK ) )
            { // ウィンドウォークとは重複しない
                pc.killSkillEffectTimer( L1SkillId.WIND_WALK );
                pc.sendPackets( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.broadcastPacket( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.setBraveSpeed( 0 );
            }
            if ( pc.hasSkillEffect( L1SkillId.STATUS_RIBRAVE ) )
            { // ユグドラの実とは重複しない
                pc.killSkillEffectTimer( L1SkillId.STATUS_RIBRAVE );
                // XXX ユグドラの実のアイコンを消す方法が不明
                pc.setBraveSpeed( 0 );
            }
            if ( pc.hasSkillEffect( L1SkillId.BLOODLUST ) )
            { // ブラッドラストとは重複しない
                pc.killSkillEffectTimer( L1SkillId.BLOODLUST );
                pc.sendPackets( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.broadcastPacket( new S_SkillBrave( pc.getId(), 0, 0 ) );
                pc.setBraveSpeed( 0 );
            }

            pc.setSkillEffect( L1SkillId.STATUS_BRAVE, timeMillis );

            int objId = pc.getId();
            pc.sendPackets( new S_SkillBrave( objId, 1, timeMillis / 1000 ) );
            pc.broadcastPacket( new S_SkillBrave( objId, 1, 0 ) );
            pc.sendPackets( new S_SkillSound( objId, 751 ) );
            pc.broadcastPacket( new S_SkillSound( objId, 751 ) );
            pc.setBraveSpeed( 1 );
        }
    }
}
